import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { NavigationMenu } from 'src/types/navigation_menu.interface';

@Injectable()
export class NavigationMenuService {
    //构造函数，通过InjectModel这个参数装饰器注入Banner模型
    constructor(@InjectModel('NavigationMenu') private navigationMenuModel: Model<NavigationMenu>) {

    }
    async find(query): Promise<NavigationMenu[]> {
        return this.navigationMenuModel.find(query).exec();
    }
    async create(createNavigationMenuDTO: NavigationMenu | NavigationMenu[]): Promise<NavigationMenu | NavigationMenu[]> {
        if (Array.isArray(createNavigationMenuDTO)) {
            return this.navigationMenuModel.insertMany(createNavigationMenuDTO)
        } else {
            return new this.navigationMenuModel(createNavigationMenuDTO).save()
        }
    }
}
